package com.al.interest;

import java.awt.*;
import java.awt.event.KeyEvent;

/**
 * 实现一个聊天轰炸器
 */
public class Boom {
    //设置轰炸次数
    private static int count = 20;
    //设置每次循环的间隔时间
    private static int time = 1500;

    public static void main(String[] args) throws AWTException {
        Robot robot = new Robot();
        //使用这个程序必须先将发送内容复制好，并打开聊天窗口
        //所以我们预留5秒做准备
        System.out.println("复制好内容打开聊天框，五秒后开始轰炸");
        for (int i = 5; i > 0; i--){
            System.out.println(i + "秒");
            robot.delay(1000);
        }
        System.out.println("开始");
        for (int i = 0; i < count; i++){
            //同时按下 ctrl+v 粘贴好，然后同时释放ctrl+v
            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_CONTROL);
            robot.keyRelease(KeyEvent.VK_V);
            //让轰炸有间隔进行
            robot.delay(time);
            //按下回车让信息发送
            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);
        }
    }
}
